<?php
namespace app\index\model;
use think\Model;
use think\Session;

/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 3/28 0028
 * Time: 19:30
 */
class User extends Model
{

    /**
     * 检查合法性
     */
    public function check(){
        $res=$this->where("username",request()->param("username"))->find();
        if ($res){
            if($res["password"]==md5(request()->param("password"))){
                Session::set("userinfo",["userid"=>$res["id"],"username"=>$res["username"],"roleid"=>$res["roleid"]]);//记录用户信息
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }

    /**
     * 修改密码
     * @return false|int
     */
    public function modifypwd(){
        $res=$this->where("id",Session::get("userinfo.userid"))->update(["password"=>md5(request()->param("password"))]);
        return $res;
    }
}